#! /bin/sh
## docker
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce -y
systemctl start docker
cat <<EOF > /etc/docker/daemon.json
{"exec-opts": ["native.cgroupdriver=systemd"]}
EOF
systemctl restart docker
docker version
systemctl enable docker

## K8S

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=0
enable=1
EOF
yum install -y kubelet kubeadm kubectl kubernetes-cni
setenforce 0
swapoff -a
systemctl stop firewalld && systemctl disable firewalld

IF $1 == "master" then
kubeadm init \
--kubernetes-version=v1.22.4 \
--control-plane-endpoint=192.168.1.244 \
--apiserver-advertise-address=192.168.1.244 \
--image-repository=registry.aliyuncs.com/google_containers \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=swap \
--upload-certs --v=6
end

echo "export KUBECONFIG=/etc/kubernetes/admin.conf">>~/.bash_profile
source ~/.bash_profile

IF $1 == "master" then
docker pull quay.io/coreos/flannel:v0.10.0-s390x
docker tag quay.io/coreos/flannel:v0.10.0-s390x quay-mirror.qiniu.com/coreos/flannel:v0.10.0-s390x
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
end

